<?php
//检查是否是某些特殊，比如移动充值号码等，这些是不允许注册
function isSpecialMobile($mobile) {
	$mobile = strval($mobile);
	if(in_array($mobile, array('13800138000'), true)){
		return 1;
	}
	return 0;
}
//检查是否是比较常见的手机号，采取提交的时候不发送，到激活的时候再让用户点重新发送
function isGoodMobile($mobile) {
	return 0;
}
//检查该手机号是否已存在
function checkMobileExist($mobile){
	return !bdb_sp_check_mobile_can_register($mobile);
}
function check_mobile_rainbow_exist($mobile,$pwd){//检查手机号跟彩虹号一样的时候密码是不是也一样
	$errorCode = '';
	$others = Transform_Goodid2Others($mobile,$errorCode);
	if(is_array($others) && isset($others['uin'])){
		$errorCodes = '';
		$uin_others = Transform_Uin2Entire($others['uin'], $errorCodes);
		if($uin_others['pwd'] == md5($pwd)) return true;
	}
	return false;
}
//给手机发送验证码短信
function send_sms($mobile,$verify){
	//发送限制，每个手机号10分钟内只能发送5次
	$key = 'send_sms_mobile_'.$mobile;
	$sendCount = intval(Mcache::read(MCACHE_SEND_SMS_MOBILE, $key));	
	if($sendCount)
	{
		Mcache::increment(MCACHE_SEND_SMS_MOBILE, $key, 1);	//缓存+1
		if($sendCount>=5){
			return 1;
		}
	}
	else 
	{
		Mcache::write(MCACHE_SEND_SMS_MOBILE, $key, 1,600);	//缓存10分钟
	}
	
	//每个IP30分钟内只能发送150次
	$key = 'send_sms_ip_'.get_client_ip_from_ns(true);
	$sendCount = intval(Mcache::read(MCACHE_SEND_SMS_IP, $key));
	if($sendCount)
	{
		Mcache::increment(MCACHE_SEND_SMS_IP, $key, 1);	//缓存+1
		if($sendCount>=150){
			return 2;
		}
	}
	else 
	{
		Mcache::write(MCACHE_SEND_SMS_IP, $key, 1,1800);//缓存30分钟
	}

	$fr = 'reg_x5';
	$msg = "尊敬的用户，您的验证码为：".$verify."（5分钟后失效）。感谢您注册《51新炫舞》。";
	$msg = iconv("UTF-8", "GB2312", $msg);	
	$time = time();
	$secret_key = '^51gerx5*awp$';
	$key = md5(substr(md5($fr . $mobile), 5, 10).substr(md5($msg . $time), 20, 5).$secret_key);
	$url = "http://m.51.com/etone/interface/send.php?fr=".$fr."&to=".$mobile."&msg=".$msg."&time=".$time."&key=".$key;
	$ctx = stream_context_create(array('http' => array('timeout' => 3)));
	$ret = file_get_contents($url,false,$ctx);
	//$ret[0]==1,success;else:fail
	return 0;
}